//
//  CalculatorButtonRow.swift
//  ToDo
//
//  Created by yanhangpu on 2021/7/7.
//

import SwiftUI

struct CalculatorButtonRow: View {

    let row:Array<CalculatorButtonItem>

    @Binding var brain: CalculatorBrain
    
    var body: some View {
        HStack {
            ForEach(self.row, id: \.self) { item in
                CalculatorButton(title: item.title, size: item.size, fontSize: item.buttonFont, foregroundColor: .white, backgroundColorName: item.backgroundColorName, cornerRadius: item.buttonCornerRadius, action: {
                    print("CalculatorButtonRow: \(item.title)")
                    self.brain = self.brain.apply(item: item)
                })
            }
        }
    }
}

struct CalculatorButtonRow_Previews: PreviewProvider {
    static var previews: some View {
        CalculatorButtonRow(row: [.digit(1), .digit(2), .digit(3), .operation(.plus)], brain: .constant(.left("0")))
    }
}
